import axios from '@/libs/api.request'

/**
 * @author Dinosaur
 * @microservice oauth-server
 * @description 根据工号获取用户信息
 * @param { String } code 工号
 * @returns { Object } 用户信息
 */
export const getUserByCode = (code) => {
  return axios.request({
    url: '/uaa/user/getUserInfo',
    method: 'GET',
    params: {
      code: code
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 获得所有学院
 * @returns 学院列表
 */
export const getInstituteList = () => {
  return axios.request({
    url: '/labm/getInstitute',
    method: 'GET'
  })
}

/**
 * @author Dinosaur
 * @microservice information
 * @description 获得所有教师
 * @param { String } institue 学院
 * @returns 教师列表
 */
export const getTeacherList = (institute) => {
  return axios.request({
    url: '/info/tea/getTeachersByInstitute',
    method: 'GET',
    params: {
      institute: institute || ''
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 根据 教师工号 获取教师的所有课程
 * @param {String} teacherCode
 * @returns 课程列表
 */
export const getCourseByTeacherCode = (teacherCode) => {
  return axios.request({
    url: '/labm/course/getByTeacherCode',
    method: 'GET',
    params: {
      teacherCode: teacherCode
    }
  })
}
// export const getCourseByTeacherCode = () => {
//   return axios.request({
//     url: '/labm/course/getByTeacherCode',
//     method: 'GET'
//   })
// }

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 获取某一时间下（周次/星期/节次）可用的实验室列表
 * @param {Number/Array} time
 * @returns 实验室列表
 */
export const getLabByTime = (time) => {
  return axios.request({
    url: '/labm/lab/getLabByUsageTime',
    method: 'POST',
    data: time
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 获取某一时间段下（周次/星期/节次）可用的实验室列表
 * @param {Array} times
 * @returns 实验室列表
 */
export const getLabByTimes = (times, institute, appCode) => {
  return axios.request({
    url: '/labm/lab/getAvailableLabCourse',
    method: 'POST',
    data: {
      'expTimeItemsCourse': times,
      'expTimeItemsTrain': undefined,
      'app_code': appCode || '',
      'institute': institute || ''
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 获取某学院可用的实验室列表
 * @param {String} institute
 * @returns 实验室列表
 */
export const getLabByInstitute = (institute) => {
  return axios.request({
    url: '/labm/lab/getAllByInstitute',
    method: 'POST',
    params: {
      institute: institute || ''
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 根据 课程代码 ，查询对应的班级信息
 * @param {String} courseCode
 * @returns 班级信息
 */
export const getClassesByCourse = (courseCode, teacherCode) => {
  return axios.request({
    url: '/labm/teachObject/getByCourseCodeAndTeacherCode',
    method: 'GET',
    params: {
      courseCode: courseCode,
      teacherCode: teacherCode
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 提交申请表
 * @data {String} data
 * @returns 是否添加成功
 */
export const submitApply = (data) => {
  return axios.request({
    url: '/labm/app/addTable',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 根据 年级 和 学院 获取专业
 * @param {String} grade
 * @param {String} institute
 * @returns 专业列表
 */
export const getMajorByGradeAndInstitute = (grade, institute) => {
  return axios.request({
    url: '/labm/teachObject/getMajorByGrade',
    method: 'GET',
    params: {
      grade: grade,
      institute: institute || ''
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 实训，获取某一时间下（ Date to Date）可用的实验室列表
 * @param {String} institute
 * @param {String} appCode
 * @param {Array} time
 * @returns 实验室列表
 */
export const getLabByDates = (institute, appCode, item) => {
  return axios.request({
    url: '/labm/lab/getAvailableLabTrain',
    method: 'POST',
    data: {
      'expTimeItemsCourse': undefined,
      'expTimeItemsTrain': item,
      'app_code': appCode || '',
      'institute': institute || ''
    }
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 根据申请表的唯一 appCode 获取申请表的详细信息
 * @url {String} appCode
 * @returns 申请表详细信息
 */
export const getFormDetailByCode = (appCode) => {
  return axios.request({
    url: '/labm/app/getDetailTable/' + appCode,
    method: 'GET'
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 修改申请表
 * @data {String} data
 * @returns 是否修改成功
 */
export const editApply = (data) => {
  return axios.request({
    url: '/labm/app/modifyTable',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 修改普通课程基本信息
 * @data {String} data
 * @returns 是否修改成功
 */
export const updateCourseBase = (data) => {
  return axios.request({
    url: '/labm/app/updateCourseInfo',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 添加普通课程单个子实验
 * @data {String} data
 * @returns 是否添加成功
 */
export const addCourseSingleExp = (data) => {
  return axios.request({
    url: '/labm/exp/add',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 修改普通课程单个子实验
 * @data {String} data
 * @returns 是否修改成功
 */
export const updateCourseSingleExp = (data) => {
  return axios.request({
    url: '/labm/exp/updateSingle',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 修改实训基本信息
 * @data {String} data
 * @returns 是否修改成功
 */
export const updateTrainingBase = (data) => {
  return axios.request({
    url: '/labm/app/updateCourseInfo/train',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 添加实训单个子实验
 * @data {String} data
 * @returns 是否添加成功
 */
export const addTrainingSingleExp = (data) => {
  return axios.request({
    url: '/labm/exp/add/train',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}

/**
 * @author Dinosaur
 * @microservice labmanager
 * @description 修改实训单个子实验
 * @data {String} data
 * @returns 是否修改成功
 */
export const updateTrainingSingleExp = (data) => {
  return axios.request({
    url: '/labm/exp/updateSingle/train',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  })
}
